package com.google.android.material.internal;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.appcompat.widget.LinearLayoutCompat;
import o.aqu.n;
import o.asa;

@RestrictTo({d.LIBRARY_GROUP})
public class ForegroundLinearLayout extends LinearLayoutCompat {
    private int ʽ;
    private final Rect ˊ;
    boolean ˋ;
    private final Rect ˎ;
    protected boolean ˏ;
    private Drawable ॱ;

    public ForegroundLinearLayout(Context context) {
        this(context, null);
    }

    public ForegroundLinearLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ForegroundLinearLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊ = new Rect();
        this.ˎ = new Rect();
        this.ʽ = 119;
        this.ˏ = true;
        this.ˋ = false;
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ʻʼ, i, 0, new int[0]);
        this.ʽ = ॱ.getInt(n.ʻʽ, this.ʽ);
        Drawable drawable = ॱ.getDrawable(n.ʻʻ);
        if (drawable != null) {
            setForeground(drawable);
        }
        this.ˏ = ॱ.getBoolean(n.ʴ, true);
        ॱ.recycle();
    }

    public int getForegroundGravity() {
        return this.ʽ;
    }

    public void setForegroundGravity(int i) {
        if (this.ʽ != i) {
            int i2;
            if ((8388615 & i) == 0) {
                i2 = 8388611 | i;
            } else {
                i2 = i;
            }
            if ((i2 & 112) == 0) {
                i2 |= 48;
            }
            this.ʽ = i2;
            if (this.ʽ == 119 && this.ॱ != null) {
                this.ॱ.getPadding(new Rect());
            }
            requestLayout();
        }
    }

    protected boolean verifyDrawable(Drawable drawable) {
        return super.verifyDrawable(drawable) || drawable == this.ॱ;
    }

    @RequiresApi(11)
    public void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();
        if (this.ॱ != null) {
            this.ॱ.jumpToCurrentState();
        }
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        if (this.ॱ != null && this.ॱ.isStateful()) {
            this.ॱ.setState(getDrawableState());
        }
    }

    public void setForeground(Drawable drawable) {
        if (this.ॱ != drawable) {
            if (this.ॱ != null) {
                this.ॱ.setCallback(null);
                unscheduleDrawable(this.ॱ);
            }
            this.ॱ = drawable;
            if (drawable != null) {
                setWillNotDraw(false);
                drawable.setCallback(this);
                if (drawable.isStateful()) {
                    drawable.setState(getDrawableState());
                }
                if (this.ʽ == 119) {
                    drawable.getPadding(new Rect());
                }
            } else {
                setWillNotDraw(true);
            }
            requestLayout();
            invalidate();
        }
    }

    public Drawable getForeground() {
        return this.ॱ;
    }

    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        this.ˋ |= z;
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        this.ˋ = true;
    }

    public void draw(@NonNull Canvas canvas) {
        super.draw(canvas);
        if (this.ॱ != null) {
            Drawable drawable = this.ॱ;
            if (this.ˋ) {
                this.ˋ = false;
                Rect rect = this.ˊ;
                Rect rect2 = this.ˎ;
                int right = getRight() - getLeft();
                int bottom = getBottom() - getTop();
                if (this.ˏ) {
                    rect.set(0, 0, right, bottom);
                } else {
                    rect.set(getPaddingLeft(), getPaddingTop(), right - getPaddingRight(), bottom - getPaddingBottom());
                }
                Gravity.apply(this.ʽ, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), rect, rect2);
                drawable.setBounds(rect2);
            }
            drawable.draw(canvas);
        }
    }

    @RequiresApi(21)
    @TargetApi(21)
    public void drawableHotspotChanged(float f, float f2) {
        super.drawableHotspotChanged(f, f2);
        if (this.ॱ != null) {
            this.ॱ.setHotspot(f, f2);
        }
    }
}
